﻿using ExpressionTree;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionTreeTest
{
    public class MyOrm<T>
    {
        StringBuilder sqlBuilder = new StringBuilder();
        public MyOrm<T> Select(Expression<Func<T,object>> exp)
        {
            sqlBuilder.AppendFormat("select {0} from {1} ", ExpressionCore.GetDefaultExpresstionHandler().Handler(exp),typeof(T).Name);
            return this;
        }
        public MyOrm<T> Where(Expression<Func<T, bool>> exp)
        {
            var conditon = ExpressionCore.GetDefaultExpresstionHandler().Handler(exp);
            if(!string.IsNullOrEmpty(conditon)&&!string.IsNullOrWhiteSpace(conditon))
            {
                sqlBuilder.AppendFormat(" where {0}", conditon);
            }
            return this;
        }
        public override string ToString()
        {
            return sqlBuilder.ToString();
        }
    }
}
